import { createRouter, createWebHistory } from "vue-router";

import login from "../views/login.vue";
import layout from "../layout/layout.vue";
let routes = [
  {
    path: "/login",
    name: "login",
    component: login,
    meta: {
      title: "登录",
    },
  },

  {
    path: "/",
    name: "layout",
    component: layout,
    redirect: "/first/a", // 重定向到第一个页面
    children: [
      {
        path: "/first", //一级菜单 不承担跳转任务
        meta: {
          title: "一级菜单",
        },
        children: [
          {
            path: "/first/a", //二级菜单 承担跳转任务
            name: "a",
            component: () => import("../views/a.vue"),
            meta: {
              title: "第一个业务页面",
            },
          },
          {
            path: "/first/b", //二级菜单 承担跳转任务
            name: "b",
            component: () => import("../views/b.vue"),
            meta: {
              title: "第二个业务页面",
            },
          },
        ],
      },
      {
        path: "/second", //一级菜单 不承担跳转任务
        meta: {
          title: "一级菜单",
        },
        children: [
          {
            path: "/second/c", //二级菜单 承担跳转任务
            name: "c",
            component: () => import("../views/c.vue"),
            meta: {
              title: "第三个业务页面",
            },
          },
        ],
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  // 路由守卫 在这里写逻辑

  next();
});

export default router;
